package com.mlming.controller;

import com.mlming.controller.frontend.MainPageController;
import com.mlming.controller.superadmin.HeadLineOperationController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 请求分发器
 */
@WebServlet("/") // 接收所有的请求
public class DispatcherServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1) 获得请求路径以及请求方法
        String requestPath = req.getServletPath();
        String requestMethod = req.getMethod();
        // 2) 根据请求路径以及请求方法, 调用对应的Controller类进行
        if("/frontend/getmainpageinfo".equals(requestPath) && "GET".equals(requestMethod)) {
            new MainPageController().getMainPageInfo(req,resp);
        } else if("/superadmin/addheadline".equals(requestPath) && "POST".equals(requestMethod)) {
            new HeadLineOperationController().addHeadLine(req,resp);
        }
    }
}
